<!--我的卡包 信用卡-->
<template>
  <div>
    <!-- <van-nav-bar title="我的信用卡" left-arrow @click-left="$router.back()" class="black">
    </van-nav-bar> -->
    <div class="body-box oh" style="height:100vh;overflow: auto;">
      <!-- 信用卡列表 -->
      <div>
          <!-- 卡列表 -->
          <div class="body-box h-100v">
            <ul class="pad-30 card-list"  v-if="Cardlist&&Cardlist.length!=0">
              <li
                class="fff mag-b-20"
                v-for="(v,k) in Cardlist"
                :key="k"
                @click="cardEditFun(v)"
              >
                <div class="fiex">
                  <div class="back-logo-box">
                    <img
                      class="back-logo"
                      :src="v.bankCode|fmtBankimsrc"
                    />
                  </div>
                  <div class="f-40 mag-l-30">{{v.bankCode|backName}}【{{v.bankCard|backOrder}}】</div>
                </div>
                <div class="mag-t-100 f-40">
                  <div class="fiex f-left">
                    <div class="fiex1">账单日:{{v.statementDate}}</div>
                    <div class="fiex1">还款日:{{v.repaymentDate}}</div>
                    <div style="margin-top:-0.15rem;">
                      距离还款日:
                      <span class="f-50">{{v.countDown}}</span> 天
                    </div>
                  </div>
                </div>
              </li>
            </ul>
             <div @click="addCard" class="bg-fff f-45 blue fiex pad-20" style="margin: 12px; justify-content: center;">
              <div class="mag-r-20"><i class="fa fa-plus"></i></div>
              <div>添加信用卡</div>
            </div>
          </div>
      </div>
      <div>
        
      </div>
      <!-- 头部切换end -->
    </div>
    <!-- 添加卡 -->
    <!-- <van-popup v-model="show" position="bottom">
      <div @click="addJumCard('CC')" class="vont-bottom pad-20">信用卡</div>
      <div @click="addJumCard('SC')" class="vont-bottom pad-20">储蓄卡</div>
    </van-popup> -->
  </div>
</template>

<script>
var self = "";
export default {
  data() {
    return {
      count: 0, //刷新次数
      selFoot: 1,
      isLoading: false, //刷新状态
      stopplan: false,
      tostopa: false,
      tostop: false,
      isActive: false,
      Cardlist: {},
      userId:""//用户id
    };
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    // self = this;
    //  try {
    //   if(self.appEquipment.indexOf("Android") >-1){
    //      android.nativeMonitorButton("0","1");
    //   }else{
    //       window.webkit.messageHandlers.nativeMonitorButton.postMessage({
    //       back:"0",
    //       colse: "1"
    //     });
    //   }
      
    // } catch (error) {
    // }
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {
    self = this;
    self.userid =  localStorage.getItem("Userid"); 
    self.init(); //加载数据
  },
  components: {},
  //方法定义
  methods: {
    cardEditFun(v) { //卡编辑
        localStorage.setItem("cardEditData",JSON.stringify(v)); //存储卡详情
        self.$router.push('/cardEdit');
    },
     addCard() {
      //添加信用卡
      axios
        .get("https://community.1818pay.cn/customer/customer/feignCustomerInfo", {
          //是否实名
          params: {
            customerId: self.userid
          }
        })
        .then(res => {
          if (res.data.code == "1000") {
             var ress = JSON.parse(res.data.data);
            if (ress.nameState == 1) {
              self.$router.push("/addCard");
            } else {
              return $th.$toast("请先实名");
            }
          } else {
            return $th.$toast(res.data.message);
          }
        });
    },
    addJumCard(type) {
      //添加卡 type: SC”储蓄卡，“CC”信用卡
      self.show = false;
      setTimeout(() => {
        if (type == "SC") {
          self.$router.push("/addSavingsDepositCard");
          return;
        }
        if (type == "CC") {
          self.$router.push("/addCardPage");
          return;
        }
      }, 100);

      // $router.push('/addSavingsDepositCard')
    },
    async init() {
      var getCard = await this.$axios(
        "https://community.1818pay.cn//customer/bankCard/findList",
        {
          //接口列表
          type: "2", //1.储蓄  2.信用
          token: localStorage.getItem("token")
        },
        "get"
      );
      // 加载状态结束
      self.loading = false;
      self.finished = true;
      self.isLoading = false;
      if (getCard.code == 1000) {
        //存储用户登录的卡信息
        self.Cardlist = getCard.data;
        console.log("Cardlist",self.Cardlist)
        //计算还款日期
        if (self.Cardlist.length != 0) {
          $.each(self.Cardlist, function(k, v) {
            v.countDown = self.$fmthkdate(v.statementDate, v.repaymentDate); //计算还款日期
          });
        }
      } else {
        return;
      }
    },
    selTitle(val) {
      //标签切换
      if (val == 0) {
        //信用卡
        this.$router.push("/creditCardPage");
        return;
      }
      if (val == 1) {
        //储蓄卡
        this.$router.push("/savingsDepositCard");
        return;
      }
    }
  }
};
</script>
<style scoped>
/* @import url(); 引入css类 */
@import "./index.css";
</style>